package model;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * User: Станислав
 * Date: 30.08.14
 */

@Component
public class Army {
    @Autowired
    private Unit.Cavalry[] cavalries;
    @Autowired
    private Unit.Infantry[] infantries;
    @Autowired
    private Hero hero;

    public Army(Unit.Cavalry[] cavalries, Unit.Infantry[] infantries, Hero hero) {
        this.cavalries = cavalries;
        this.infantries = infantries;
        this.hero = hero;
    }
    public Army(){}

    public Unit.Cavalry[] getCavalries() {
        return cavalries;
    }

    public void setCavalries(Unit.Cavalry[] cavalries) {
        this.cavalries = cavalries;
    }

    public Unit.Infantry[] getInfantries() {
        return infantries;
    }

    public void setInfantries(Unit.Infantry[] infantries) {
        this.infantries = infantries;
    }

    public Hero getHero() {
        return hero;
    }

    public void setHero(Hero hero) {
        this.hero = hero;
    }

    public Army armyFactory(int calvary, int infants, String nameHero) {
        this.cavalries = new Unit.Cavalry[calvary];
        this.infantries = new Unit.Infantry[infants];
        int heroHp = calvary+infants;
        int heroLevel = heroHp/10;
        this.hero = new Hero(heroHp,heroLevel,nameHero);
        return new Army(cavalries,infantries,hero);
    }

    @Override
    public String toString() {
        return "Army{" +
                "cavalries=" + (cavalries == null ? null : Arrays.asList(cavalries)) +
                ", infantries=" + (infantries == null ? null : Arrays.asList(infantries)) +
                ", hero=" + hero +
                '}';
    }
}
